package exception;

import java.io.FileOutputStream;

//本类用来演示异常体系解决io的异常演示demo
public class FinallyDemo2 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try{
            fos = new FileOutputStream("fos.txt");//如果实例化未成功，fos就是一个空的，下面再调用close就会报空指针异常
            fos.write(97);
        }catch (Exception e){
            System.out.println("出错了");
        }finally {
            System.out.println("进入finally");
          try{
              if(fos != null){
                  fos.close();
              }
          }catch (Exception e){
              System.out.println("关闭文件出错");
          }
        }

    }
}
